#ifndef MONITORPRO_M_PHPREDIS
#define MONITORPRO_M_PHPREDIS

#include "php_monitorpro.h"

#include <string>

// typedef struct {
//     short gc;
//     size_t len;
//     char *val;
// } zend_string;

// typedef struct fold_item {
//     zval * (*fun)(INTERNAL_FUNCTION_PARAMETERS, void *, ...);
//     void *ctx;
//     struct fold_item *next;
// } fold_item;

// /* {{{ struct RedisSock */
// typedef struct {
//     php_stream     *stream;
//     zend_string    *host;
//     short          port;
//     zend_string    *auth;
//     double         timeout;
//     double         read_timeout;
//     long           retry_interval;
//     int            failed;
//     int            status;
//     int            persistent;
//     int            watching;
//     zend_string    *persistent_id;

//     int            serializer;
//     int            compression;
//     long           dbNumber;

//     zend_string    *prefix;

//     short          mode;
//     fold_item      *head;
//     fold_item      *current;

//     char           *pipeline_cmd;
//     size_t         pipeline_len;

//     zend_string    *err;

//     zend_bool      lazy_connect;

//     int            scan;

//     int            readonly;
//     int            tcp_keepalive;
// } RedisSock;
// /* }}} */

// #if (PHP_MAJOR_VERSION < 7)
// typedef struct {
//     zend_object std;
//     RedisSock *sock;
// } redis_object;
// #else
// typedef struct {
//     RedisSock *sock;
//     zend_object std;
// } redis_object;
// #endif
////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef enum {ATOMIC, MULTI, PIPELINE} redis_mode;

typedef struct fold_item {
    zval * (*fun)(INTERNAL_FUNCTION_PARAMETERS, void *, ...);
    void *ctx;
    struct fold_item *next;
} fold_item;

typedef struct request_item {
    char *request_str; 
    int request_size; /* size_t */
    struct request_item *next;
} request_item;

/* {{{ struct RedisSock */
typedef struct {
    php_stream     *stream;
    char           *host;
    short          port;
    char           *auth;
    double         timeout;
    double         read_timeout;
    long           retry_interval;
    int            failed;
    int            status;
    int            persistent;
    int            watching;
    char           *persistent_id;

    int            serializer;
    long           dbNumber;

    char           *prefix;
    int            prefix_len;

    redis_mode     mode;
    fold_item      *head;
    fold_item      *current;

    request_item   *pipeline_head;
    request_item   *pipeline_current;

    char           *err;
    int            err_len;
    zend_bool      lazy_connect;

    int            scan;

    int            readonly;
} RedisSock;

void monitorpro_phpredis_handler(zend_execute_data *execute_data, long start_micro_time, long end_micro_time, std::string class_name, std::string function_name);


#endif